18 #include "clock_config.h" 20 #include "fsl_debug_console.h" 22 #ifndef CPU_LPC55S16JBD100 25 #include "fsl_usart.h" 27 #include "fsl_common.h" 28 #include "freemaster.h" 29 #include "freemaster_serial_uart.h" 33 #include "Driver_I2C.h" 38 #include "issdk_hal.h" 39 #include "gpio_driver.h" 46 #define FXLS896x_NUM_REGISTERS (FXLS896x_SELF_TEST_CONFIG2 + 1) 47 #define FF_A_FFMT_THS (0x08) 48 #define A_FFMT_COUNT (0x18) 49 #define PL_COUNT (0x15) 50 #define ASLP_COUNTER (0x07) 51 #define ACCEL_2G_SENS (0.000976) 52 #define ACCEL_4G_SENS (0.001953) 53 #define ACCEL_8G_SENS (0.003906) 54 #define ACCEL_16G_SENS (0.007813) 56 #define RAW_ACCEL_DATA_SIZE (6U) 57 #define MAX8BITSTORAGE (255U) 58 #define FXLS896x_DATA_SIZE 6 163 uint8_t read_trigger;
165 uint8_t readall_size;
166 uint8_t readall_trigger;
168 uint8_t trigger_accel_offnoise;
169 uint8_t trigger_selftest;
174 uint8_t dataready_cntr;
192 uint8_t complete_accel_offnoise;
204 uint8_t complete_selftest;
243 static FMSTR_U8 recBuffer[1024*10];
249 static unsigned char pipe3_rxb[512];
250 static unsigned char pipe3_txb[0x1000];
254 int16_t
XSTP[2]={0,0},
YSTP[2]={0,0},
ZSTP[2]={0,0},
XSTN[2]={0,0},
YSTN[2]={0,0},
ZSTN[2]={0,0};
265 static void init_freemaster_uart(
void);
397 FMSTR_TSA_TABLE_END()
399 FMSTR_TSA_TABLE_LIST_BEGIN()
400 FMSTR_TSA_TABLE(main_table)
401 FMSTR_TSA_TABLE_LIST_END()
414 recBuffCfg.name =
"FXLS896x 3-Axis Accelerometer Data";
447 init_freemaster_uart();
451 if (ARM_DRIVER_OK != status)
457 status = I2Cdrv->PowerControl(ARM_POWER_FULL);
458 if (ARM_DRIVER_OK != status)
464 status = I2Cdrv->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_FAST);
465 if (ARM_DRIVER_OK != status)
495 FMSTR_HPIPE hpipe = FMSTR_PipeOpen(3, NULL, (FMSTR_ADDR)pipe3_rxb,
sizeof(pipe3_rxb), (FMSTR_ADDR)pipe3_txb,
sizeof(pipe3_txb),
496 FMSTR_PIPE_TYPE_ANSI_TERMINAL,
"streaming");
586 if (ARM_DRIVER_OK != status)
605 rawData.
accel[0] = (int16_t)(((int16_t)(((int16_t)registers.
reg_addr[3] << 8) | registers.
reg_addr[2])));
606 rawData.
accel[1] = (int16_t)(((int16_t)(((int16_t)registers.
reg_addr[5] << 8) | registers.
reg_addr[4])));
607 rawData.
accel[2] = (int16_t)(((int16_t)(((int16_t)registers.
reg_addr[7] << 8) | registers.
reg_addr[6])));
624 else if ((regdata & FXLS896x_SENS_CONFIG1_FSR_MASK) == 4)
628 else if ((regdata & FXLS896x_SENS_CONFIG1_FSR_MASK) == 6)
638 registers.
accel[0] = (float) (rawData.
accel[0] * sensitivity);
639 registers.
accel[1] = (float) (rawData.
accel[1] * sensitivity);
640 registers.
accel[2] = (float) (rawData.
accel[2] * sensitivity);
820 offnoiseptr->
offx = 0.0;
821 offnoiseptr->
offy = 0.0;
822 offnoiseptr->
offz = 0.0;
823 offnoiseptr->
rmsx = 0.0;
824 offnoiseptr->
rmsy = 0.0;
825 offnoiseptr->
rmsz = 0.0;
835 static uint16_t cntr=0;
839 static float xx[
N], yy[
N], zz[
N];
840 static float xm[
N], ym[
N], zm[
N];
841 static float xsq[
N], ysq[
N], zsq[
N];
843 static float sumx=0.0;
844 static float sumy=0.0;
845 static float sumz=0.0;
855 am[0]=rawData->
accel[0]*sens;
856 am[1]=rawData->
accel[1]*sens;
857 am[2]=rawData->
accel[2]*sens;
877 offnoiseptr->
offx=0-sumx;
878 offnoiseptr->
offy=0-sumy;
879 offnoiseptr->
offz=1-sumz;
888 xsq[j]=(float)pow(xm[j],2);
889 ysq[j]=(float)pow(ym[j],2);
890 zsq[j]=(float)pow(zm[j],2);
900 offnoiseptr->
rmsx=(float)pow(stdx,0.5);
901 offnoiseptr->
rmsy=(float)pow(stdy,0.5);
902 offnoiseptr->
rmsz=(float)pow(stdz,0.5);
909 sumx = sumy = sumz = 0;
910 stdx = stdy = stdz = 0;
952 if (ARM_DRIVER_OK != status)
958 for(counter=0;counter<1;counter++)
971 if (ARM_DRIVER_OK != status)
982 if (ARM_DRIVER_OK != status)
1022 static void init_freemaster_uart(
void)
1024 uart_config_t config;
1035 UART_GetDefaultConfig(&config);
1036 config.baudRate_Bps = 115200U;
1037 config.enableTx =
false;
1038 config.enableRx =
false;
1043 FMSTR_SerialSetBaseAddress((UART_Type*)BOARD_DEBUG_UART_BASEADDR);
1045 #if FMSTR_SHORT_INTR || FMSTR_LONG_INTR 1052 #if FMSTR_SHORT_INTR || FMSTR_LONG_INTR 1070 #if defined __CORTEX_M && (__CORTEX_M == 4U) const registerreadlist_t cFXLS896x_whoami[]
int32_t perform_selftest(fxls896x_i2c_sensorhandle_t fxls896xDriver, fxls896x_selftest_t *selftest)
Function to perform FXLS896x self test.
#define FXLS896x_I2C_ADDR
enum fxls896x_operation_type fxls896x_operation_type_t
This structure defines the fxls896x host operation type.
The fxls896x_drv.h file describes the FXLS8964/67AF driver interface and structures.
#define FXLS896x_SENS_CONFIG2_ANIC_TEMP_EN
This structure defines the Write command List.
#define FXLS896x_SENS_CONFIG1_FSR_4G
const registerreadlist_t cFXLS896x_fs_src[]
Prepare the register read for FullScale range Register.
#define FXLS896x_SENS_CONFIG3_WAKE_ODR_12_5HZ
#define I2C_S_SIGNAL_EVENT
status_t SMC_SetPowerModeVlpr(void *arg)
Configures the system to VLPR power mode. API name used from Kinetis family to maintain compatibility...
const registerwritelist_t cFxls896xSTXN[]
Register settings for Self-Test in X Axis (Negative polarity).
int32_t Register_I2C_Write(ARM_DRIVER_I2C *pCommDrv, registerDeviceInfo_t *devInfo, uint16_t slaveAddress, uint8_t offset, uint8_t value, uint8_t mask, bool repeatedStart)
The interface function to write a sensor register.
This structure defines the fxls896x all registers metadata.
#define FXLS896x_SENS_CONFIG1_ST_POL_POSITIVE
void BOARD_DELAY_ms(uint32_t delay_ms)
Function to insert delays.
uint8_t complete_accel_offnoise
int main(void)
Main function.
int32_t apply_register_readall(fxls896x_i2c_sensorhandle_t fxls896xDriver)
Function to apply FXLS896x register read-all operation.
#define BOARD_BootClockRUN
int32_t FXLS896x_I2C_Initialize(fxls896x_i2c_sensorhandle_t *pSensorHandle, ARM_DRIVER_I2C *pBus, uint8_t index, uint16_t sAddress, uint8_t *whoami)
The interface function to initialize the sensor.
Access structure of the GPIO Driver.
registerDeviceInfo_t deviceInfo
const registerwritelist_t cFxls896xSTZN[]
Register settings for Self-Test in Z Axis (Negative polarity).
int32_t apply_register_read(fxls896x_i2c_sensorhandle_t fxls896xDriver, uint8_t offset, uint8_t *value)
Function to apply FXLS896x register read operation.
const registerreadlist_t cFxls896xOutputNormal[]
Address of Raw Accel Data in Normal Mode.
uint8_t complete_selftest
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_MASK
#define FXLS896x_SENS_CONFIG1_FSR_16G
const registerwritelist_t cFxls896xSTYP[]
Register settings for Self-Test in Y Axis (Positive polarity).
const registerreadlist_t FXLS896x_ALL_REG_READ[]
FXLS896x register list to read all registers.
This structure defines variables to compute self-test output change (STOC) and self-test offset (STOF...
#define __END_WRITE_DATA__
const registerwritelist_t cFxls896xSTYN[]
Register settings for Self-Test in Y Axis (Negative polarity).
#define FXLS896x_DATA_SIZE
#define BOARD_DEBUG_UART_CLK_FREQ
typedef int32_t(DATA_FORMAT_Append_t))(void *pData
The interface function to append the data on the formated stream.
void BOARD_InitDebugConsole(void)
int32_t apply_register_write(fxls896x_i2c_sensorhandle_t fxls896xDriver, uint8_t offset, uint8_t value)
Function to apply FXLS896x register write operation.
#define FXLS896x_NUM_REGISTERS
This structure defines the fxls896x raw data buffer.
#define FXLS896x_SENS_CONFIG1_ST_POL_MASK
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_EN_Z
const registerwritelist_t cFxls896xConfigNormal[]
Defines the register write list to configure FXLS896x in Interrupt mode.
void accel_off_noise(fxls896x_acceldata_t *rawData, fxls896x_offset_noise_t *offnoiseptr, float sens)
Function to measure accelerometer offset noise.
#define FXLS896x_SENS_CONFIG1_ST_POL_NEGATIVE
This structure defines the fxls896x offset and noise calculation parameters.
void(* registeridlefunction_t)(void *userParam)
This is the register idle function type.
#define FXLS896x_SENS_CONFIG1_FSR_MASK
fxls896x_operation_type
This structure defines the fxls8962 host operation type.
GENERIC_DRIVER_GPIO * pGpioDriver
#define FXLS896x_INT_EN_DRDY_EN_MASK
This defines the sensor specific information for I2C.
uint32_t BOARD_SystickElapsedTime_us(int32_t *pStart)
Function to compute the Elapsed Time.
fxls896x_allregs_t registers
FMSTR_REC_BUFF recBuffCfg
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_EN_Y
fxls896x_offset_noise_t offnoise_data
int32_t FXLS896x_I2C_Configure(fxls896x_i2c_sensorhandle_t *pSensorHandle, const registerwritelist_t *pRegWriteList)
The interface function to configure he sensor.
#define __END_READ_DATA__
int32_t FXLS896x_I2C_ReadData(fxls896x_i2c_sensorhandle_t *pSensorHandle, const registerreadlist_t *pReadList, uint8_t *pBuffer)
The interface function to read the sensor data.
FMSTR_TSA_TABLE_BEGIN(main_table)
Target Side Addressable (TSA) table created for this application.
void offset_noise_init(fxls896x_offset_noise_t *offnoiseptr)
Function to initialize offset noise measurement.
#define FXLS896x_SENS_CONFIG2_ANIC_TEMP_MASK
void fxls896x_isr_callback(void *pUserData)
ISR for FXLS896x interrupt source event.
int32_t update_dropdown_selection(fxls896x_allregs_t *registers, uint8_t caller)
Function to update dropdown selection.
void selftest_init(fxls896x_selftest_t *selftest)
Function to initialize FXLS896x self test metadata.
fxls896x_i2c_sensorhandle_t fxls896xDriver
void FXLS896x_I2C_SetIdleTask(fxls896x_i2c_sensorhandle_t *pSensorHandle, registeridlefunction_t idleTask, void *userParam)
: The interface function to set the I2C Idle Task.
#define BOARD_DEBUG_UART_BASEADDR
void(* toggle_pin)(pinID_t aPinId)
volatile bool bFxls896xIntFlag
uint8_t reg_addr[FXLS896x_NUM_REGISTERS]
void BOARD_SystickEnable(void)
Function to enable systicks framework.
status_t SMC_SetPowerModeWait(void *arg)
Configures the system to WAIT power mode. API name used from Kinetis family to maintain compatibility...
void(* pin_init)(pinID_t aPinId, gpio_direction_t dir, void *apPinConfig, gpio_isr_handler_t aIsrHandler, void *apUserData)
GENERIC_DRIVER_GPIO Driver_GPIO_KSDK
This structure defines the Read command List.
const registerreadlist_t cFXLS896x_int_src[]
Prepare the register read for INT Status Register.
gpioHandleKSDK_t GREEN_LED
const registerwritelist_t cFxls896xSTZP[]
Register settings for Self-Test in Z Axis (Positive polarity).
#define I2C_S_DEVICE_INDEX
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_DISABLED
void BOARD_InitPins(void)
Configures pin routing and optionally pin electrical features.
#define FXLS896x_SENS_CONFIG1_ST_AXIS_SEL_EN_X
uint8_t trigger_accel_offnoise
fxls896x_selftest_t selftest
fxls896x_acceldata_t rawData
#define FXLS896x_INT_EN_DRDY_EN_EN
#define FXLS896x_SENS_CONFIG3_WAKE_ODR_MASK
uint8_t readall_value[FXLS896x_NUM_REGISTERS]
#define BOARD_UART_IRQ_HANDLER
This structure defines the fxls8962 raw data buffer.
uint8_t byte_data[sizeof(sensor_data)]
const registerwritelist_t cFxls896xSTXP[]
Register settings for Self-Test in X Axis (Positive polarity).